<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>注册步骤1</h1>
    姓名: <input class="username" type="text" /><br />
    年龄: <input class="age" type="text" /><br />
    <button>下一步</button>
    <script>
      let usernameEle = document.querySelector(".username");
      let ageEle = document.querySelector(".age");
      //判断sessionStorage里有没有内容  有的话就自动填充到输入框里面getItem
      if (sessionStorage.getItem("username")) {
        usernameEle.value = sessionStorage.getItem("username");
      }
      if (sessionStorage.getItem("age")) {
        ageEle.value = sessionStorage.getItem("age");
      }

      document.querySelector("button").onclick = function () {
        let username = usernameEle.value;
        let age = ageEle.value;

        sessionStorage.setItem("username", username);
        sessionStorage.setItem("age", age);
        window.location.href = "./b.html";
      };
    </script>
  </body>
</html>
